package o;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.webkit.WebView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedHashMap;
import o.der.f;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class enr {
    public static void ˎ(Context context, String str) {
        String str2 = null;
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (jSONObject.has("appDetailId")) {
                String optString;
                String optString2 = jSONObject.optString("appDetailId");
                if (jSONObject.has("directory")) {
                    optString = jSONObject.optString("directory");
                } else {
                    optString = null;
                }
                if (jSONObject.has("channelNo")) {
                    str2 = jSONObject.optString("channelNo");
                }
                ens.ॱ(context, optString2, optString, str2);
                int ॱ = ccz.ॱ();
                if (context instanceof Activity) {
                    ॱ = dgm.ˎ((Activity) context);
                }
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put("detailid", optString2);
                linkedHashMap.put("service_type", String.valueOf(ॱ));
                dgh.ˋ("wap_item_click", linkedHashMap);
            }
        } catch (JSONException e) {
            Logger.ˋ("UserJsControl", "UserJsControl:toDetailPage() exception is: " + e.toString());
        }
    }

    public static String ˎ(final Context context, final WebView webView, Handler handler) {
        boolean ॱ = euf.ˎ().ॱ();
        if (!ॱ) {
            final d dVar = new d();
            handler.post(new Runnable() {
                public void run() {
                    CharSequence string = context.getString(f.ˎͺ);
                    CharSequence string2 = context.getString(f.ʻʼ, new Object[]{enr.ॱ(webView)});
                    CharSequence string3 = context.getString(f.ॱʾ);
                    CharSequence string4 = context.getString(f.ⁱ);
                    cku ˏ = cku.ˏ(context, cku.class, string, string2);
                    ˏ.ˎ(context);
                    ˏ.ॱ(-2, string3);
                    ˏ.ॱ(-1, string4);
                    ˏ.ॱ(new cks(this) {
                        final /* synthetic */ AnonymousClass1 ˎ;

                        {
                            this.ˎ = r1;
                        }

                        public void enableNetworking() {
                            dVar.ˋ = true;
                            euf.ˎ().ˏ(true);
                        }

                        public void upgrade() {
                            dVar.ˋ = true;
                            euf.ˎ().ˏ(false);
                        }

                        public void ˋ() {
                        }
                    });
                    ˏ.ॱ(new ewe(this) {
                        final /* synthetic */ AnonymousClass1 ˏ;

                        {
                            this.ˏ = r1;
                        }

                        public void ॱ() {
                            dVar.ˋ = true;
                            euf.ˎ().ˏ(false);
                        }
                    });
                }
            });
            while (!dVar.ˋ) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Logger.e("UserJsControl", "catch a InterruptedException");
                }
            }
            ॱ = euf.ˎ().ॱ();
        }
        if (ॱ) {
            return dof.ʼ(UserSession.getInstance().getUserName());
        }
        return null;
    }

    private static String ॱ(WebView webView) {
        String url = webView.getUrl();
        try {
            url = new URL(webView.getUrl()).getHost();
        } catch (MalformedURLException e) {
            Logger.e("UserJsControl", "getHost() error ");
        }
        return url;
    }

    public static void ˊ(final Context context, final azt o_azt, final Handler handler) {
        handler.post(new Runnable() {
            public void run() {
                if (doo.ˊ(context)) {
                    eoj.ˋ().ˎ("refreshST", new AccountBussinessListener(this) {
                        final /* synthetic */ AnonymousClass5 ˎ;

                        {
                            this.ˎ = r1;
                        }

                        public void onAccountBusinessResult(ccp o_ccp) {
                            Logger.ˏ("UserJsControl", "refreshST finished , will refresh Url, accountResult=" + o_ccp);
                            if (102 == o_ccp.ˎ) {
                                handler.post(new Runnable(this) {
                                    final /* synthetic */ AnonymousClass5 ॱ;

                                    {
                                        this.ॱ = r1;
                                    }

                                    public void run() {
                                        if (o_azt != null) {
                                            o_azt.ˊॱ();
                                        }
                                    }
                                });
                            }
                            eoj.ˋ().ˊ("refreshST");
                        }
                    });
                    eod.ˊ(context, eoq.ˏ("st_error_retry"), false, true, false);
                    return;
                }
                evk.ˏ(context, f.ʻʽ, 0).ˋ();
            }
        });
    }
}
